package com.cloudsigns.factorymanager2.engineering.presenter;

import com.cloudsigns.factorymanager2.engineering.IView.InSendPatrolOrderView;
import com.cloudsigns.factorymanager2.engineering.model.InSendPatrolOrderModel;
import com.cloudsigns.factorymanager2.engineering.model.SendPatrolOrderModel;

/**
 * Created by tony on 2018/5/19.
 */

public class SendPatrolOrderPresenter {
    private InSendPatrolOrderView view;
    private InSendPatrolOrderModel model;
    private android.os.Handler mHandler = new android.os.Handler();

    public SendPatrolOrderPresenter(InSendPatrolOrderView view) {
        this.view = view;
        this.model = new SendPatrolOrderModel();
    }

    public void sendPatrolOrder() {


        model.sendPatrolOrder(view.getId(), view.getEngineeringPatrolOrderSendItemRequestList(), new SendPatrolOrderModel.OnSendPatrolOrderListener() {
            @Override
            public void sendPatrolOrderSuccessed() {
                //需要在UI线程执行
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.sendPatrolOrderSuccess();
                        view.hideLoading();
                    }
                });
            }

            @Override
            public void sendPatrolOrderFailed(final String desc) {
                mHandler.post(new Runnable() {
                    @Override
                    public void run() {
                        view.sendPatrolOrderFailed(desc);
                        view.hideLoading();
                    }
                });
            }


        });
    }
}
